package Test;

import java.util.Arrays;

public class test {

    public static void insertSort(int[] array){
        for(int i = 1; i < array.length; i ++){
            int tmp = array[i];
            int j = i - 1;
            for(; j >= 0; j--) {
                if (array[j] > tmp) {
                    array[j + 1] = array[j];
                }else {
                    break;
                }
            }
            array[j + 1] = tmp;
        }
    }

    public static void main(String[] args) {
        int[] array = {3, 5, 9, 3,  4, 7};
        System.out.println(Arrays.toString(array));

        insertSort(array);
        System.out.println("排序后:" + Arrays.toString(array));
    }
}
